// 1.对于数据请求的封装

// import axios from "axios";
// function httpForList(params) {
//   return axios({
//     url: `https://m.maizuo.com/gateway?filmId=${params}&k=106604`,
//     headers: {
//       "X-Client-Info":
//         '{"a":"3000","ch":"1002","v":"5.2.0","e":"16481780177384775358676993","bc":"440100"}',
//       "X-Host": " mall.film-ticket.film.info",
//     },
//   });
// }

// export default {
//   httpForList,
// };

//2.对数据的请求的封装
import axios from "axios";
import { Toast } from "vant";
const http = axios.create({
  baseURL: "https://m.maizuo.com",
  timeout: 10000,
  headers: {
    "X-Client-Info":
      '{"a":"3000","ch":"1002","v":"5.2.0","e":"16481780177384775358676993","bc":"440100"}',
  },
});

// 在请求之前拦截  --showloding
http.interceptors.request.use(
  function (config) {
    // Do something before request is sent
    // 默认2秒关闭  设置duration为0永远不停 需要在后面清空
    Toast.loading({
      message: "加载中...",
      forbidClick: true,
      duration: 0,
    });
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// 在请求之后拦截 --hideLoding
http.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    // 隐藏 清空taost
    Toast.clear();

    return response;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    // 隐藏 清空taost
    Toast.clear();
    return Promise.reject(error);
  }
);

export default http;
